#ifndef RENDERER_H
#define RENDERER_H
//----------------------------------
//directx
#include<D3DX9.h>
#include<D3D9.h>
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
//----------------------------------
#include "VertexBuffer.h"
#include "Structs.h"
#include "Defines.h"
#include "Texture.h"
//----------------------------------
class ENGINE_API Renderer
{
public:
	//----------------------------------
	//Constructor y destructor
	Renderer(HWND p_hWnd);
	~Renderer();
	//----------------------------------
	//DirectX
	bool InitDX(HWND p_hWnd);//Inicializador de directX
	//----------------------------------
	//Matrices
	void LoadIdentity ();
	void SetMatrixMode (MatrixMode p_MatrixMode);
	//----------------------------------
	//Dibujado en pantalla
	void StartFrame();
	void EndFrame();
	//----------------------------------
	//Entity
	void RotateZ (float p_fAngle);
	void RotateX (float p_fAngle);
	void RotateY (float p_fAngle);
	void Translate (float p_fX, float p_fY, float p_fZ = 0.0f);
	void Scale (float p_fW, float p_fH);
	void Draw(ColorVertex * p_vertexColletion, PrimitiveType p_PrimType, unsigned int p_uiVertexCount);
	//----------------------------------
	//Texturas
	bool BindTexture(Texture* p_pTextur);
	bool LoadTexture(Texture* p_rkTexture);
	void Draw(TextureVertex * p_textureColletion, PrimitiveType p_PrimType, unsigned int p_uiVertexCount);

private:
	IDirect3DDevice9* m_pD3D9Device;	//nuestro directx
	D3DXVECTOR3 m_vViewerPos;		//la posicion de la vista
	D3DXVECTOR3 m_vViewerUp;		//el arriba de la vista
	D3DXVECTOR3 m_vEyePos;
	VertexBuffer<ColorVertex,COLOR_VERTEX> m_VertexBuffer;	
	VertexBuffer<TextureVertex, TEXTURE_VERTEX> m_TextureBuffer;
	MatrixMode m_CurrentMatMode;	//El modo de matriz que estamos utilizando en este momento, sea de vista o de mundo.
	//----------------------------------------------------------------------------------
	HWND m_hWnd;					//nuestra ventana
	D3DPRESENT_PARAMETERS m_d3dPresentParameters; //parametros de directx
	HRESULT m_hr;	//Cada accion en directx devuelve un hresult
	D3DDISPLAYMODE m_D3DDisplayMode; //Modo de vista
	std::map<std::string, IDirect3DTexture9*> m_mTextureMap; //Mapa de texturas
	std::map<std::string, IDirect3DTexture9*>::iterator m_miTextureIterator; //Iterador del mapa
};
#endif